using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using Newtonsoft.Json;
namespace googleViewLib
{
    public class EDSWebClient : WebClient
    {
        //time in milliseconds
        private int timeout;
        public int Timeout
        {
            get
            {
                return timeout;
            }
            set
            {
                timeout = value;
            }
        }

        public EDSWebClient()
        {
            this.timeout = 60000;
        }

        public EDSWebClient(int timeout)
        {
            this.timeout = timeout;
        }

        protected override WebRequest GetWebRequest(Uri address)
        {
            WebRequest result = base.GetWebRequest(address);
            result.Timeout = this.timeout;
            return result;
        }
    }
    public class GoogleAPI
    {
        public static void test()
        { 
            string url = "https://ajax.googleapis.com/ajax/services/search/web?v=1.0&"
    + "q=Paris%20Hilton&userip=USERS-IP-ADDRESS" ;
            EDSWebClient client = new EDSWebClient(20000);
            client.Encoding = Encoding.UTF8;
            client.Headers.Add("user-agent", "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.10) Gecko/2009042316 Firefox/3.0.10)");
            string content = client.DownloadString(url);

            Dictionary<string, object> values = JsonConvert.DeserializeObject<Dictionary<string, object>>(content);
          
           Newtonsoft.Json.Linq.JObject data = (Newtonsoft.Json.Linq.JObject)values["responseData"];
          // Console.WriteLine(data.First[");                              
        }
        public static void main(string[] args)
        {
            test();
        }
    }
}
